#include <stdio.h>
#include <stdint.h>

typedef struct st_pktHead {
    uint16_t id;
    uint16_t end :  1;
    uint16_t ack :  1;
    uint16_t len : 14;
} __attribute__((packed)) st_pktHead_t;

int main(void) 
{
    st_pktHead_t pktHead;
    pktHead.id = 0x1234;
    pktHead.end = 1;
    pktHead.ack = 1;
    pktHead.len = 0x3678;

    printf("sizeof(st_pktHead_t) = %ld\r\n", sizeof(st_pktHead_t));
    printf("sizeof(pktHead) = %ld\r\n", sizeof(pktHead));
    printf("pktHead.id = 0x%x, pktHead.end = %hhd, pktHead.ack = %hhd, pktHead.len = 0x%x\r\n",
		    pktHead.id, pktHead.end, pktHead.ack, pktHead.len);

    printf("(uint32_t)pktHead = 0x%x\r\n", *(uint32_t*)&pktHead);
    printf("(uint16_t)pktHead = 0x%x\r\n", *(uint16_t*)&pktHead);
    printf("(uint16_t)pktHead = 0x%x\r\n", *(1+(uint16_t*)&pktHead));	// NOTE: add 1, NOT 2
    
    return 0;
}
